/**
 * Project Name:template-web
 * File Name   :TypeComparator.java
 * Package Name:org.cn.template.component.kindeditor
 * Date:2015年9月27日下午3:38:04
 * Copyright (c) 2015, http://my.oschina.net/httpssl All Rights Reserved.
 *
*/

package org.cn.template.component.kindeditor;

import java.util.Comparator;
import java.util.Hashtable;

/**
 * ClassName:TypeComparator <br/>
 * Function :TODO ADD FUNCTION. <br/>
 * Reason	:TODO ADD REASON. <br/>
 * Date     :2015年9月27日 下午3:38:04 <br/>
 * @author  :http://my.oschina.net/httpssl
 * @email   :491835898@QQ.COM
 * @since   :JDK 1.7
 * @see 	 
 */
public class TypeComparator implements Comparator<Object>
{

	@Override
	public int compare(Object a, Object b) {
		Hashtable<?, ?> hashA = (Hashtable<?, ?>)a;
		Hashtable<?, ?> hashB = (Hashtable<?, ?>)b;
		if (((Boolean)hashA.get("is_dir")) && !((Boolean)hashB.get("is_dir"))) {
			return -1;
		} else if (!((Boolean)hashA.get("is_dir")) && ((Boolean)hashB.get("is_dir"))) {
			return 1;
		} else {
			return ((String)hashA.get("filetype")).compareTo((String)hashB.get("filetype"));
		}
	}

}
